var httpsUrl = getApp().globalData.httpsUrl;
var globalData = getApp().globalData;
var commonUtil = require("../../../utils/commonUtil.js")
Page({

  data: {
    imgUrl: globalData.imgUrl,
    list: [],
    pageNumber:1,
    pageSize:10,
    totalPage:1,
  },
  list: function () {
    var that = this;
    var params = new Object();
    params.pageNumber = this.data.pageNumber;
    params.pageSize = this.data.pageSize;
    console.log("params:" + JSON.stringify(params));
    let openId = wx.getStorageSync("openidKey");
    commonUtil.showLoading("加载中...");
    wx.request({
      url: httpsUrl + "/commoissionRecord/list",
      header: { "openId": openId, "content-Type": "application/x-www-form-urlencoded" },
      dataType: "json",
      method: "GET",
      data: params,
      success: function (res) {
        commonUtil.hideLoading();
        res = res.data;
        console.log("code:" + JSON.stringify(res.result));
        console.log("res:" + JSON.stringify(res));
        if (res.result == 0) {
          var rows = res.data.list;
          if (rows != null && rows.length > 0) {
            for (let i = 0; i < rows.length; i++) {
              if (!commonUtil.isEmpty(rows[i].commission_balance)) {
                rows[i].commission_balance = rows[i].commission_balance.toFixed(2);
              }
            }
          }
          that.setData({ totalPage: res.data.totalPage })
          if (that.data.pageNumber == 1) {
            that.setData({ list: rows })
          } else {
            var list = that.data.list;
            list = list.concat(rows);
            that.setData({ list: list })
          }
        } else {
          commonUtil.showModal(res.msg);
        }
      }
    })
  },

  onLoad: function (options) {
    this.list();
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let pageNumber = this.data.pageNumber;
    pageNumber = pageNumber + 1;
    if (pageNumber > this.data.totalPage) {
      commonUtil.showSuccessToast("没有更多啦~");
      return;
    } else {
      this.setData({ pageNumber: pageNumber })
      this.list();
    }
  },
})